package deftoolbar

import (
	"yunj/pkg/yunj/core/builder/builderaction"
	"yunj/pkg/yunj/core/builder/builderconsts"
)

// 数据导入
type Import struct {
	Action
}

func NewImport(title ...string) *Import {
	a := &Import{}

	builderaction.SetActionInstance(&a.Action.Action, a)
	a.SetActionCode("import")
	if len(title) > 0 {
		a.SetTitle(title[0])
	}
	return a
}

// 设置标题
func (a *Import) SetTitle(title string) *Import {
	a.Title = title
	return a
}

// 设置额外的class或图标类名
func (a *Import) SetClass(class string) *Import {
	a.Class = class
	return a
}

// 设置权限
func (a *Import) SetAuth(auth string) *Import {
	a.Auth = auth
	return a
}

// 处理属性
func (a *Import) HandleAttr() error {
	// 设置默认值
	a.Type = builderconsts.EVENT_OPEN_POPUP
	if a.Title == "" {
		a.Title = "数据导入"
	}
	if a.Class == "" {
		a.Class = "layui-icon-upload"
	}
	return nil
}
